home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 17.9 KB | 626 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: CMovieFac.cpp
- // Release Version: $ 1.0d1 $
- //
- // Author: Lonnie Millett
- // Creation Date: 3/28/94
- //
- // Copyright: © 1993, 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef MOVIEFAC_H
- #include "MovieFac.h"
- #endif
-
- #ifndef MOVIEFRA_H
- #include "MovieFra.h"
- #endif
-
- #ifndef MOVIEPAR_H
- #include "MoviePar.h"
- #endif
-
- #ifndef MOVIESEL_H
- #include "MovieSel.h"
- #endif
-
- // ----- Framework Includes -----
-
- #ifndef FWMEMMGR_H
- #include <FWMemMgr.h>
- #endif
-
- #ifndef FWGRDEF_H
- #include "FWGrDef.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef _FACET_
- #include <Facet.h>
- #endif
-
- #ifndef _FRAME_
- #include <Frame.h>
- #endif
-
- #ifndef _SHAPE_
- #include <Shape.h>
- #endif
-
- #ifndef _WINDOW_
- #include <Window.h>
- #endif
-
- #ifndef _TRNSFRMM_
- #include <TrnsfrmM.h>
- #endif
-
- #ifndef _EXCEPT_
- #include <Except.h>
- #endif
-
- #ifndef _XMPSESSM_
- #include <XMPSessM.h>
- #endif
-
- #ifndef _TRANSLAT_
- #include <Translat.h>
- #endif
-
- #ifndef _DRAGDROP_
- #include <DragDrop.h>
- #endif
-
- #ifndef _DGITMITR_
- #include <DgItmItr.h>
- #endif
-
- #ifndef _STDPROPS_
- #include <StdProps.h>
- #endif
-
- #ifndef _STDTYPES_
- #include <StdTypes.h>
- #endif
-
- #ifndef _STORAGEU_
- #include <StorageU.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__QUICKDRAW__)
- #include <Quickdraw.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__RESOURCES__)
- #include <Resources.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(mathRoutinesIncludes)
- #include <math routines.h>
- #endif
-
- #pragma segment MoviePart
-
- //----------------------------------------------------------------------------------------
- // CMovieFacet::CMovieFacet
- //----------------------------------------------------------------------------------------
- CMovieFacet::CMovieFacet()
- {
- fMovie = NULL;
- fMovieController = NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFacet::~CMovieFacet
- //----------------------------------------------------------------------------------------
- CMovieFacet::~CMovieFacet()
- {
- if (fMovieController)
- {
- DisposeMovieController(fMovieController);
- fMovieController = NULL;
- }
-
- if (fMovie)
- {
- DisposeMovie(fMovie);
- fMovie = NULL;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFacet::InitMovieFacet
- //----------------------------------------------------------------------------------------
- void CMovieFacet::InitMovieFacet(XMPFacet* xmpFacet, CMovieFrame* movieFrame)
- {
- this->InitFacet(xmpFacet);
- fMovieFrame = movieFrame;
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFacet::GetMoviePart()
- //----------------------------------------------------------------------------------------
- inline CMoviePart* CMovieFacet::GetMoviePart() const
- {
- return fMovieFrame->GetMoviePart();
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFacet::GetMovieBoundingBox
- //----------------------------------------------------------------------------------------
- void CMovieFacet::GetMovieBoundingBox(FW_CRect* boundingBox)
- {
- if (fMovie)
- {
- FW_SPlatformRect movieBox;
- ::GetMovieBox(fMovie, &movieBox);
-
- if (this->GetMovieFrame()->IsActive())
- movieBox.bottom += 16;
- *boundingBox = movieBox;
- }
- else
- *boundingBox = this->GetMoviePart()->GetDefaultPicture()->GetRectangle();
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFacet::SetMovie
- //----------------------------------------------------------------------------------------
- void CMovieFacet::SetMovie(Movie newMovie)
- {
- if (newMovie)
- {
- if (fMovieController)
- {
- DisposeMovieController(fMovieController);
- fMovieController = NULL;
- }
-
- if (fMovie)
- {
- DisposeMovie(fMovie);
- fMovie = NULL;
- }
-
- fMovie = newMovie;
-
- ::SetMovieGWorld(fMovie,(CGrafPtr)this->GetXMPWindow()->GetPlatformWindow(), NULL);
-
- FW_SPlatformRect movieBox;
- ::GetMovieBox(fMovie, &movieBox);
- if (::EmptyRect(&movieBox))
- ::SetRect(&movieBox, 0, 0, 100, 100);
- fMovieController = ::NewMovieController(fMovie, &movieBox, mcTopLeftMovie+mcWithBadge+mcNotVisible);
- THROW_IF_NULL(fMovieController);
- ::MCDoAction(fMovieController, mcActionSetKeysEnabled, (Ptr)TRUE);
- ::MCDoAction(fMovieController, mcActionSetUseBadge, (Ptr)TRUE);
- ::MCEnableEditing(fMovieController, TRUE);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFacet::AdjustMovieBox
- //----------------------------------------------------------------------------------------
- void CMovieFacet::AdjustMovieBox()
- {
- FW_CRect boundingBox;
- fMovieFrame->GetFrameShapeBounds(&boundingBox);
-
- if (fMovie)
- {
- FW_SPlatformRect movieBox;
-
- if (fMovieFrame->IsRoot())
- boundingBox.bottom -= ff(16);
- boundingBox.Place(ff(0), ff(0));
- boundingBox.AsPlatformRect(movieBox);
-
- ::SetMovieBox(fMovie, &movieBox);
- THROW_IF_ERROR(::MCMovieChanged(fMovieController, fMovie), "::MCMovieChanged");
- }
- else
- this->GetMoviePart()->GetDefaultPicture()->SetRectangle(boundingBox);
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFacet::ClipShapeChanged
- //----------------------------------------------------------------------------------------
- void CMovieFacet::ClipShapeChanged()
- {
- if (fMovieController)
- {
- FW_PlatformRegion movieClipRegion;
- FW_PlatformRegion clipRegion;
-
- clipRegion = ::NewRgn();
- ::CopyRgn(this->GetXMPFacet()->GetClipShape()->GetQDRegion(), clipRegion);
-
- movieClipRegion = ::GetMovieDisplayBoundsRgn(fMovie);
- ::SectRgn(clipRegion, movieClipRegion, movieClipRegion);
-
- THROW_IF_ERROR(::MCSetClip(fMovieController, clipRegion, movieClipRegion), "::MCSetClip");
-
- ::DisposeRgn(clipRegion);
- ::DisposeRgn(movieClipRegion);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFacet::StartMovie
- //----------------------------------------------------------------------------------------
- void CMovieFacet::StartMovie()
- {
- if (fMovieController)
- {
- Fixed playRate = ::GetMoviePreferredRate(fMovie);
- ::MCDoAction(fMovieController, mcActionPlay, (Ptr)playRate);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFacet::StopMovie
- //----------------------------------------------------------------------------------------
- void CMovieFacet::StopMovie()
- {
- if (fMovieController)
- ::MCDoAction(fMovieController, mcActionPlay, (Ptr)0);
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFacet::SetMovieLooping
- //----------------------------------------------------------------------------------------
- void CMovieFacet::SetMovieLooping(FW_Boolean loop)
- {
- if (fMovieController)
- ::MCDoAction(fMovieController, mcActionSetLooping, (Ptr)loop);
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFacet::Draw
- //----------------------------------------------------------------------------------------
- void CMovieFacet::Draw(FW_CGraphicContext *gc)
- {
- if (fMovieController != NULL)
- ::MCDraw(fMovieController, this->GetXMPFacet()->GetWindow()->GetPlatformWindow());
- else
- this->GetMoviePart()->GetDefaultPicture()->Draw(gc);
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFacet::GeometryChanged
- //----------------------------------------------------------------------------------------
- void CMovieFacet::GeometryChanged()
- {
- FW_CFacet::GeometryChanged();
-
- FW_CRect boundingBox;
- fMovieFrame->GetFrameShapeBounds(&boundingBox);
-
- FW_CRect movieBox;
- this->GetMovieBoundingBox(&movieBox);
-
- if (boundingBox != movieBox)
- this->AdjustMovieBox();
-
- this->ClipShapeChanged();
- }
-
- //------------------------------------------------------------------------------
- // CMovieFacet::WindowActivated
- //------------------------------------------------------------------------------
-
- void CMovieFacet::WindowActivated()
- {
- this->DoMovieActivate(TRUE);
- }
-
- //------------------------------------------------------------------------------
- // CMovieFacet::WindowDeActivated
- //------------------------------------------------------------------------------
-
- void CMovieFacet::WindowDeActivated()
- {
- this->DoMovieActivate(FALSE);
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFacet::DoMouseDown
- //----------------------------------------------------------------------------------------
- FW_Boolean CMovieFacet::DoMouseDown(const FW_CPoint& where, XMPEventData event)
- {
- FW_Boolean eventHandled = FALSE;
-
- if (fMovieController)
- {
- FW_CGraphicContext gc(this->GetXMPFacet());
-
- FW_SPlatformPoint originalWhere;
- ::SetPt(&originalWhere, event->where.h, event->where.v);
-
- FW_CPoint offset(0,0);
- offset = this->GetContentTransform()->TransformPoint(offset);
- ::SetOrigin(-(offset.IntX()), -(offset.IntY()));
-
- event->where.h = where.IntX(); event->where.v = where.IntY();
- eventHandled = (FW_Boolean)::MCClick(fMovieController, this->GetXMPFacet()->GetWindow()->GetPlatformWindow(),
- event->where, event->when, event->modifiers);
-
- ::SetPt(&event->where, originalWhere.h, originalWhere.v);
-
- this->GetFrame()->GetPart()->GetSelection()->Drag(this, event);
- }
-
- return eventHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFacet::DoMovieKey
- //----------------------------------------------------------------------------------------
- FW_Boolean CMovieFacet::DoMovieKey(XMPEventData event)
- {
- FW_Boolean eventHandled = FALSE;
-
- if (fMovieController)
- {
- FW_CGraphicContext gc(this->GetXMPFacet());
-
- eventHandled = (FW_Boolean)::MCKey(fMovieController, (char)event->message, event->modifiers);
- }
-
- return eventHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFacet::DoMovieSetVisible
- //----------------------------------------------------------------------------------------
- void CMovieFacet::DoMovieSetVisible(FW_Boolean visible)
- {
- if (fMovieController)
- {
- FW_CGraphicContext gc(this->GetXMPFacet());
-
- THROW_IF_ERROR(::MCSetVisible(fMovieController, visible), "::MCSetVisible");
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFacet::DoMovieIdle
- //----------------------------------------------------------------------------------------
- FW_Boolean CMovieFacet::DoMovieIdle()
- {
- FW_Boolean eventHandled = FALSE;
-
- if (fMovieController)
- {
- FW_CGraphicContext gc(this->GetXMPFacet());
-
- eventHandled = (FW_Boolean)::MCIdle(fMovieController);
- }
-
- return eventHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFacet::DoMovieActivate
- //----------------------------------------------------------------------------------------
- void CMovieFacet::DoMovieActivate(FW_Boolean activate)
- {
- if (fMovieController)
- {
- FW_CGraphicContext gc(this->GetXMPFacet());
-
- ::MCActivate(fMovieController, this->GetXMPWindow()->GetPlatformWindow(), activate);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFacet::IsControllerVisible
- //----------------------------------------------------------------------------------------
- FW_Boolean CMovieFacet::IsControllerVisible()
- {
- if (fMovieController)
- return ::MCGetVisible(fMovieController);
- else
- return FALSE;
- }
-
- //------------------------------------------------------------------------------
- // CMovieFacet::GetCurrentSelection
- //------------------------------------------------------------------------------
- void CMovieFacet::GetCurrentSelection(TimeValue* currentTime, TimeValue* duration)
- {
- if (fMovie)
- ::GetMovieSelection(fMovie, currentTime, duration);
- }
-
- //------------------------------------------------------------------------------
- // CMovieFacet::SetCurrentSelection
- //------------------------------------------------------------------------------
- void CMovieFacet::SetCurrentSelection(TimeValue currentTime, TimeValue duration)
- {
- if (fMovie)
- {
- FW_CGraphicContext gc(this->GetXMPFacet());
-
- ::SetMovieSelection(fMovie, currentTime, duration);
- THROW_IF_ERROR(::MCMovieChanged(fMovieController, fMovie), "::MCMovieChanged");
- }
- }
-
- //------------------------------------------------------------------------------
- // CMovieFacet::IsEmpty
- //------------------------------------------------------------------------------
- FW_Boolean CMovieFacet::IsEmpty()
- {
- FW_Boolean empty = TRUE;
- if (fMovie)
- {
- TimeValue currentTime, duration;
-
- ::GetMovieSelection(fMovie, ¤tTime, &duration);
- empty = duration == (TimeValue)0;
- }
- return empty;
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFacet::CloseSelection
- //----------------------------------------------------------------------------------------
- void CMovieFacet::CloseSelection()
- {
- this->SetCurrentSelection(0, 0);
- }
-
- //------------------------------------------------------------------------------
- // CMovieFacet::ClearSelection
- //------------------------------------------------------------------------------
- void CMovieFacet::ClearSelection(TimeValue currentTime, TimeValue duration)
- {
- if (fMovieController)
- {
- FW_CGraphicContext gc(this->GetXMPFacet());
-
- this->SetCurrentSelection(currentTime, duration);
- THROW_IF_ERROR(::MCClear(fMovieController));
- }
- }
-
- //------------------------------------------------------------------------------
- // CMovieFacet::SelectAll
- //------------------------------------------------------------------------------
- void CMovieFacet::SelectAll()
- {
- if (fMovie)
- {
- FW_CGraphicContext gc(this->GetXMPFacet());
-
- this->SetCurrentSelection((TimeValue)0, ::GetMovieDuration(fMovie));
- }
- }
-
- //------------------------------------------------------------------------------
- // CMovieFacet::CopySelection
- //------------------------------------------------------------------------------
- FW_PlatformHandle CMovieFacet::CopySelection()
- {
- FW_PlatformHandle movieHandle = NULL;
- if (fMovieController)
- {
- FW_CGraphicContext gc(this->GetXMPFacet());
-
- Movie newMovie = ::MCCopy(fMovieController);
- movieHandle = ::FW_CMemoryManager::AllocateSystemHandle(0);
- THROW_IF_NULL(movieHandle);
- THROW_IF_ERROR(::PutMovieIntoHandle(newMovie, movieHandle));
- DisposeMovie(newMovie);
- }
- return movieHandle;
- }
-
- //------------------------------------------------------------------------------
- // CMovieFacet::DragEnter
- //------------------------------------------------------------------------------
- void CMovieFacet::DragEnter(XMPDragItemIterator* dragInfo, const FW_CPoint& where)
- {
- FW_CFacet::DragEnter(dragInfo, where);
-
- if (!this->GetCanAcceptDrop())
- {
- XMPStorageUnit *dragSU;
- HFSFlavor *valueData;
- long valueSize;
-
- XMPTranslation *translate = GetFrame()->GetPart()->GetSession()->GetTranslation();
- XMPType typeHFS = translate->GetISOTypeFromPlatformType('hfs ', kXMPPlatformDataType);
- XMPType typePICT = translate->GetISOTypeFromPlatformType('PICT', kXMPPlatformDataType);
- XMPType typeTEXT = translate->GetISOTypeFromPlatformType('TEXT', kXMPPlatformDataType);
- XMPType typesnd = translate->GetISOTypeFromPlatformType('snd ', kXMPPlatformDataType);
-
- for (dragSU = dragInfo->First(); dragSU; dragSU = dragInfo->Next())
- {
- if (fMovie && (dragSU->Exists(kXMPPropContents, typePICT, 0) ||
- dragSU->Exists(kXMPPropContents, typeTEXT, 0) ||
- dragSU->Exists(kXMPPropContents, typesnd, 0)))
- {
- this->SetCanAcceptDrop(TRUE);
- }
- else if (dragSU->Exists(kXMPPropContents, typeHFS, 0))
- {
- dragSU->Focus(kXMPPropContents, kXMPPosUndefined, typeHFS, 0, kXMPPosUndefined);
- valueSize = dragSU->GetSize();
- if (valueSize)
- {
- valueData = (HFSFlavor*) FW_CMemoryManager::AllocateBlock(valueSize);
- dragSU->GetValue(valueSize, (XMPValue)valueData);
- if (valueData->fileType == 'MooV')
- this->SetCanAcceptDrop(TRUE);
- FW_CMemoryManager::FreeBlock(valueData);
- }
- }
- }
- }
- }
-
- //------------------------------------------------------------------------------
- // CMovieFacet::DrawDragHiliteInside
- //------------------------------------------------------------------------------
- FW_Boolean CMovieFacet::DrawDragHiliteInside()
- {
- if (this->GetFrame()->IsRoot())
- return TRUE;
- else
- return FALSE;
- }
-
- //------------------------------------------------------------------------------
- // CMovieFacet::GetMovieAsPict
- //------------------------------------------------------------------------------
- PicHandle CMovieFacet::GetMovieAsPict()
- {
- PicHandle moviePict = NULL;
- if (fMovie)
- moviePict = ::GetMoviePict(fMovie, ::GetMovieTime(fMovie, NULL));
- return moviePict;
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFacet::PasteMovieToSelection
- //----------------------------------------------------------------------------------------
- void CMovieFacet::PasteMovieToSelection(Movie newMovie, TimeValue currentTime, TimeValue duration)
- {
- if (fMovieController)
- {
- FW_CGraphicContext gc(this->GetXMPFacet());
-
- this->SetCurrentSelection(currentTime, duration);
- THROW_IF_ERROR(::MCPaste(fMovieController, newMovie));
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFacet::PasteHandleToSelection
- //----------------------------------------------------------------------------------------
- void CMovieFacet::PasteHandleToSelection(FW_PlatformHandle newHandle, OSType handleType, TimeValue currentTime, TimeValue duration)
- {
- if (fMovie)
- {
- FW_CGraphicContext gc(this->GetXMPFacet());
-
- this->SetCurrentSelection(currentTime, duration);
- THROW_IF_ERROR(::PasteHandleIntoMovie(newHandle, handleType, fMovie, 0, (ComponentInstance)0));
- THROW_IF_ERROR(::MCMovieChanged(fMovieController, fMovie), "::MCMovieChanged");
- }
- }
-
-